#include "RenderOption.h"
#include "MathUtil.h"

RenderOption::RenderOption(void)
{
	traceShadows = true;
	numLightSamples = 8;
	maxDepth = 9;

	computeGI = false;
	computeCaustics = false;
	numPhotons = 200000;
	numGather = 100;
	photonReductionRatio = 0.9;
	irradianceCacheTolerance = 0.05;
	irradianceCacheSpacing = 2.0;
	displayIrradianceSamples = false;

	minAASamples = 4;
	maxAASamples = 16;
	threshold = 0.001;
	displayAASamples = false;

	outputFilename = "output.hdr";
}

RenderOption::~RenderOption(void)
{
}

void RenderOption::validate()
{
	
	numLightSamples = max(0, numLightSamples);
	maxDepth = max(0, maxDepth);

	numPhotons = max(0, numPhotons);
	numGather = max(10, numGather);
	photonReductionRatio = MathUtil::clamp(photonReductionRatio, 0.0, 0.995);
	irradianceCacheTolerance = max(0.001, irradianceCacheTolerance);
	irradianceCacheSpacing = max(0.001, irradianceCacheSpacing);

	if (minAASamples < 4)
		minAASamples = 4;
	if (maxAASamples <= 1)
		minAASamples = maxAASamples = 1;
	if (minAASamples > maxAASamples)
		minAASamples = maxAASamples;
	if (minAASamples == maxAASamples)
		displayAASamples = false;
	threshold = max(0, threshold);
}

bool RenderOption::getTraceShadows()
{
	return traceShadows;
}

void RenderOption::setTraceShadows( bool traceShadows )
{
	this->traceShadows = traceShadows;
}

double RenderOption::max( double a, double b )
{
	return (a > b) ? a : b;
}

int RenderOption::getNumLightSamples()
{
	return numLightSamples;
}

void RenderOption::setNumLightSamples( int numLightSamples )
{
	this->numLightSamples = numLightSamples;
}

int RenderOption::getMaxDepth()
{
	return maxDepth;
}

void RenderOption::setMaxDepth( int maxDepth )
{
	this->maxDepth = maxDepth;
}

bool RenderOption::getComputeGI()
{
	return computeGI;
}

void RenderOption::setComputeGI( bool computeGI )
{
	this->computeGI = computeGI;
}

bool RenderOption::setComputeCaustics()
{
	return computeCaustics;
}

void RenderOption::setComputeCaustics( bool computeCaustics )
{
	this->computeCaustics = computeCaustics;
}

int RenderOption::getNumPhotons()
{
	return numPhotons;
}

void RenderOption::setNumPhotons( int numPhotons )
{
	this->numPhotons = numPhotons;
}

int RenderOption::getNumGather()
{
	return numGather;
}

void RenderOption::setNumGather( int numGather )
{
	this->numGather = numGather;
}

double RenderOption::getPhotonReductionRatio()
{
	return photonReductionRatio;
}

void RenderOption::setPhotonReductionRatio( double photonReductionRatio )
{
	this->photonReductionRatio = photonReductionRatio;
}

double RenderOption::getIrradianceCacheTolerance()
{
	return irradianceCacheTolerance;
}

void RenderOption::setIrradianceCacheTolerance( double irradianceCacheTolerance )
{
	this->irradianceCacheTolerance = irradianceCacheTolerance;
}

double RenderOption::getIrradianceCacheSpacing()
{
	return irradianceCacheSpacing;
}

void RenderOption::setIrradianceCacheSpacing( double irradianceCacheSpacing )
{
	this->irradianceCacheSpacing = irradianceCacheSpacing;
}

int RenderOption::getIrradianceSamples()
{
	return irradianceSamples;
}

void RenderOption::setIrradianceSamples( int irradianceSamples )
{
	this->irradianceSamples = irradianceSamples;
}

bool RenderOption::getDisplayIrradianceSamples()
{
	return displayIrradianceSamples;
}

void RenderOption::setDisplayIrradianceSamples( bool displayIrradianceSamples )
{
	this->displayIrradianceSamples = displayIrradianceSamples;
}

int RenderOption::getMinAASamples()
{
	return minAASamples;
}

void RenderOption::setMinAASamples( int minAASamples )
{
	this->minAASamples = minAASamples;
}

int RenderOption::getMaxAASamples()
{
	return maxAASamples;
}

void RenderOption::setMaxAASamples( int maxAASamples )
{
	this->maxAASamples = maxAASamples;
}

double RenderOption::getAAThreshold()
{
	return threshold;
}

void RenderOption::setAAThreshold( double threshold )
{
	this->threshold = threshold;
}

bool RenderOption::getDisplayAASamples()
{
	return displayAASamples;
}

void RenderOption::setDisplayAASamples( bool displayAASamples )
{
	this->displayAASamples = displayAASamples;
}

char* RenderOption::getOutputFilename()
{
	return outputFilename;
}

void RenderOption::setOutputFilename( char* outputFilename )
{
	this->outputFilename = outputFilename;
}
